<extend name="Public/base" />

<block name="body">
    <!-- 标题栏 -->

    <!-- 

        button a 标签的按钮 需要加入 class="btn btn-default" 
            删除加入 btn-danger 确认加入 btn-success;  
            h2标题后面添加返回的按钮
        
        table 需要添加 class="table table-bordered" 所有的按钮使用 icon; 外部a标签需要添加title=""提示

     -->

    <div class="main-title">
        <h2>商品列表</h2>
    </div>
    <div></div>
    <br/>
    <div class="cf">
        <div class="fl">
            <a title="新增" class="btn btn-primary" href="{:U('add')}"><i class="glyphicon glyphicon-plus"></i></a>
            <button class="btn btn-default ajax-post" url="{:U('changeStatus',array('method'=>'resume'))}" target-form="ids"><i class="glyphicon glyphicon-ok-circle"></i> 启 用</button>
            <button class="btn btn-default  ajax-post" url="{:U('changeStatus',array('method'=>'forbid'))}" target-form="ids"><i class="glyphicon glyphicon-ban-circle"></i> 禁 用</button>
            <button class="btn btn-danger ajax-post confirm" url="{:U('del')}" target-form="ids">删 除</button>
            <a class="ajax-get btn btn-default" title="新商品上架提醒" href="{:U('remind')}"><i class="glyphicon glyphicon glyphicon-bell">提醒</i></a>
        </div>

        <!-- 高级搜索 -->
        <div class="search-form fr cf">
            <div class="sleft">
                 
                <input type="text" name="title" class="search-input form-control" value="{:I('title')}" placeholder="请输入标题">
                <a class="sch-btn" href="javascript:;" id="search" url="{:U('index')}"><i class="btn-search"></i></a>
            </div>
        </div>
    </div>
    <!-- 数据列表 -->
    <div class="data-table table-striped">
    <table class="table table-bordered">
    <thead>
        <tr>
        <th class="row-selected row-selected"><input class="check-all" type="checkbox"/></th>
        <th class="">ID</th>
        <th class="">缩略图</th>
        <th class="">商品名称</th>
        <th class="">游戏</th>
        <th class="">金额 | (原价)</th>
        <th class="">库存</th>
        <th class="">状态</th>
        <th class="">更新时间</th>
        <th width="400" class="">操作</th>
        </tr>
    </thead>
    <tbody>
        <notempty name="_list">
        <volist name="_list" id="vo">
        <tr>
            <td width="1%"><input class="ids" type="checkbox" name="id[]" value="{$vo.id}" /></td>
            <td>
                {$vo.id}
            </td>
            <td width="12%"><div class="upload-img-box">
                <notempty name="vo.thumb">
                    <div class="upload-pre-item"><img src="{:url_format($vo['thumb'])}"/></div>
                </notempty>
                </div></td>
            <td width="10%">{$vo.name|htmlspecialchars_decode} </td>
            <td width="6%">{$options['game_id'][$vo['game_id']]}</td>
            <td>
            {$vo.price} | ( <font style="text-decoration: line-through">{$vo.oprice}</font> )
            </td>
            <td width="4%">
                {$vo.stock}
            </td>
            <td width="4%">
                {$vo.status_text}
            </td>
            <td width="12%">
                {$vo.updated_at|date="Y-m-d H:i",###}
            </td>
            <td>
                <a class="btn btn-default btn-xs" title="图组" href="{:U('MallGoodsThumbs/index?goods_id='.$vo['id'])}"><i class="glyphicon glyphicon-picture"></i></a>
                <a class="btn btn-default btn-xs" title="激活码" href="{:U('MallGoodsCdkeys/index?goods_id='.$vo['id'])}"><i class="glyphicon glyphicon-barcode"></i></a>
                <a class="btn btn-default btn-xs" title="编辑" href="{:U('edit?id='.$vo['id'])}"><i class="glyphicon glyphicon-pencil"></i></a>
                <a href="{:U('del?id='.$vo['id'])}" class="confirm ajax-get btn btn-danger btn-xs"><i class="glyphicon glyphicon-trash"></i></a>
                <!-- Single button -->
                <div class="btn-group">
                  <button type="button" class="btn btn-default btn-xs dropdown-toggle" data-toggle="dropdown">推荐位设置<span class="caret"></span>
                  </button>
                  <ul class="dropdown-menu" role="menu">
                    <volist name="pos" id="p">
                    <li><a href="javascript:addpos({$p.id}, {$vo.id})">{$p.name}</a></li>
                    </volist>
                    <li class="divider"></li>
                    <li><a href="{:U('pos/index')}">查看全部推荐位设置</a></li>
                  </ul>
                </div>

            </td>
        </tr>
        </volist>
        <else/>
        <td colspan="9" class="text-center"> aOh! 暂时还没有内容! </td>
        </notempty>
    </tbody>
    </table>
    </div>
    <div class="page">
        {$_page}
    </div>
    <div id="video-pre">
        <video controls="controls" autoplay="autoplay"></video>
    </div>
</block>

<block name="script">
    <script src="__STATIC__/thinkbox/jquery.thinkbox.js"></script>

    <script type="text/javascript">
    //搜索功能
    $("#search").click(function(){
        var url = $(this).attr('url');
        var query  = $('.search-form').find('input').serialize();
        query = query.replace(/(&|^)(\w*?\d*?\-*?_*?)*?=?((?=&)|(?=$))/g,'');
        query = query.replace(/^&/g,'');

        var game  = $('.search-form').find('select').serialize();
        game = game.replace(/(&|^)(\w*?\d*?\-*?_*?)*?=?((?=&)|(?=$))/g,'');
        game = game.replace(/^&/g,'');

        if( url.indexOf('?')>0 ){
            url += '&' + query + '&' + game;
        }else{
            url += '?' + query + '&' + game;
        }
        window.location.href = url;
    });
    //回车搜索
    $(".search-input").keyup(function(e){
        if(e.keyCode === 13){
            $("#search").click();
            return false;
        }
    });
    //导航高亮
    highlight_subnav('{:U('index')}');
    //视频预览
    
    function addpos(posid, target_id) {
        $.post("{:U('PosData/add')}", {posId: posid, target_id: target_id}, function (data) {
            if (data.status==1) {
                    if (data.url) {
                        updateAlert(data.info + ' 页面即将自动跳转~','alert-success');
                    }else{
                        updateAlert(data.info ,'alert-success');
                    }
                    location.reload();
                }else{
                    updateAlert(data.info);
                }
        })
    }


    </script>
</block>
